<form action="<?php echo site_url("admin/set_category_temp"); ?>" method="post"  />

 <?php 
$rows = $this->db->query("select * from meterial_base_categories order by sort_order asc")->result_array();
foreach($rows as $base){
$sql ="SELECT
material_categories.category_name,
material_categories.cat_base_id,
material_categories.category_id,


(select  COALESCE(sum( amount_total  ),0 ) from inventory_views where material_categories.category_id =  inventory_views.category_id ) as total
,(select  COALESCE(sum( allocation_total  ),0 ) from inventory_views where material_categories.category_id =  inventory_views.category_id ) as allocation_total

FROM
material_categories where type_id = $type_id and cat_base_id = ".$base['cat_base_id'];
$cats =  $this->db->query($sql)->result_array();

if(count($cats))
{

?>

<table class="list" style="width:400px;" >
          <tbody><tr class=" odd">
             <th style="width:30px;">เลือก</th>
            <th  ><?php echo $base["cat_base_name"]; ?></th>
           
           
          </tr>
         <?php
          $i = 1;
          foreach($cats as $row){ ?>
        
          <tr class="<?php if($i++%2){ echo "even";} ?>" >
            <td><input type="checkbox" value="<?php echo $row['category_id']; ?>"  name="ids[]" /></td>
            
            <td style="width:270px;"><?php echo $row['category_name']; ?></td>
         
           
          </tr>
          <?php } }  ?>
        </tbody></table>
<?php } ?>
<input type="submit" value="Submit" />
</form>